package com.xiaohudie.JUC;

/**
 * @Author xiao hu die
 * @Date 2022/1/12 22:19
 * @Version 1.0
 */

import lombok.SneakyThrows;

/**线程间定制化通信*/
class Share03{
    /**标志位*/
    private Integer a =1;
    /**A方法*/

    @SneakyThrows
    public synchronized void  A(){
        while (a!=1){
          this.wait();
        }
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName());
        }
        a=2;
        this.notifyAll();
    }
    @SneakyThrows
    public synchronized void  B (){
        while (a!=2){
            this.wait();
        }
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName());
        }
        a=3;
        this.notifyAll();
    }
    @SneakyThrows
    public synchronized void  C (){
        while (a!=3){
            this.wait();
        }
        for (int i = 0; i < 15; i++) {
            System.out.println(Thread.currentThread().getName());
        }
        a=1;
        this.notifyAll();
    }
}
public class ThreadDemo03 {
    public static void main(String[] args) {
        Share03 share03 = new Share03();
        new Thread(()->{
            share03.A();
        },"AA").start();
        new Thread(()->{
            share03.B();
        },"BB").start();
        new Thread(()->{
            share03.C();
        },"CC").start();
    }
}
